package com.example.demo.mapper;

import com.example.demo.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Insert("INSERT INTO user(user_id, username, password, gender, avatar) " +
            "VALUES(#{userId}, #{username}, #{password}, #{gender}, #{avatar})")
    int insertUser(User user);

    @Select("SELECT * FROM user WHERE user_id = #{userId}")
    User selectUserById(Long userId);

    @Select("SELECT * FROM user WHERE username = #{username}")
    User selectUserByUsername(String username);

    @Update("UPDATE user SET username=#{username}, password=#{password}, " +
            "gender=#{gender}, avatar=#{avatar} WHERE user_id=#{userId}")
    int updateUser(User user);

    @Delete("DELETE FROM user WHERE user_id = #{userId}")
    int deleteUser(Long userId);
}